package versi.vitro.oaiserviceprovider.service.exporter.impl;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.testng.annotations.Test;

import versi.vitro.oaiserviceprovider.helper.GeneralHelper;
import versi.vitro.oaiserviceprovider.service.exporter.api.ExporterService;
import versi.vitro.oaiserviceprovider.service.transformer.api.TransformerService;
import versi.vitro.oaiserviceprovider.test.BaseTestCase;

public class ExporterServiceIntegrationTest extends BaseTestCase {

    @Test
    public void testRdfToXmlTransformation() {

	final GeneralHelper generalHelper = getGeneralHelper();
	final TransformerService transformerService = getTransformerService();
	final OutputStream outputStream = new ByteArrayOutputStream();

	ExporterService exporterService = new ExporterServiceImpl(generalHelper, null, null, transformerService) {
	    protected byte[] extractRdfFromTripleStore() {
		final String resource = generalHelper.readPackageResourceAsString("test_exported.rdf", getClass());
		if (resource == null) {
		    throw new RuntimeException(
			    "Export service constructor was unable to obtain the XSLT file contents. ");
		}
		byte[] xsltBytes = resource.getBytes();
		return xsltBytes;
	    }
	    
	    protected void writeResult(byte[] resultByte) {
		try {
		    outputStream.write(resultByte);
		} catch (IOException e) {
		    throw new RuntimeException("Test GenerateExportModel output stream failed. ");
		}
	    }
	};
	exporterService.generateXmlFile();

	String pseudoFileContents = outputStream.toString();
	String actualFileContents = generalHelper.readPackageResourceAsString("test_transformed.xml", getClass());

	assert pseudoFileContents.length() == actualFileContents.length();
	assert pseudoFileContents.equals(actualFileContents);
    }
    
    // TODO RR complete test.
    @Test
    public void testRdfToXmlAgainstSchema() {
    
    }

}
